package eu.winterwheels.enterprise.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.validation.constraints.NotNull;

/**
 * Entity implementation class for Entity: Role
 *
 */
@Entity
public class Role implements Serializable {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY) //do this for auto-insert / auto-increment in MySql
	private Long id;
	@NotNull
	private String role;
	private static final long serialVersionUID = 1L;
	
	@ManyToMany(mappedBy="roles")
	private Set<User> users;
	
	private Date dateCreated;
	private Date dateModified;

	public Role() {
		super();
	}   
	
	/***** EVENT HOOKS *****/

	@PrePersist
	protected void onCreate() {
		dateCreated = new Date();
	}

	@PreUpdate
	protected void onUpdate() {
		dateModified = new Date();
	}
	
	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	/***** GETTER AND SETTERS *****/
	
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}   
	public String getRole() {
		return this.role;
	}

	public void setRole(String Role) {
		this.role = Role;
	}
   
}
